class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }
  getName() {
    return this.name
  }
}

// Handler
const getHandler = {
  get: function(obj, prop) {
    return prop in obj ? obj[prop] : '没有对应的属性'
  },
  set: function(obj, prop, value) {
    if (prop === 'age') {
      obj.age = value;
    }else {
      console.warn('不是年龄age');
    }
  }
}

const person1 = new Person('张三', 25);

const p = new Proxy(person1, getHandler)

console.log(p.name) // '张三'
console.log(p.gender) // 'alvin'
console.log(p.age) // 25
console.log(p.address) // 'alvin'
console.log(person1.address); // undefined
p.age = 30;
console.log(p.age) // 30;
p.name = '弟弟';
console.log(p.name)